<!DOCTYPE HTML>
<html  lang="zh" xmlns:th="http://www.thymeleaf.org">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-eduInfo-edit" th:object="${eduInfo}">
            <input id="empSn" name="empSn" th:field="*{empSn}" type="hidden">
            <div class="form-group">	
                <label class="col-sm-3 control-label">姓名：</label>
                <div class="col-sm-8">
                    <input id="empNm" name="empNm" th:field="*{empNm}" class="form-control" type="text" readonly="readonly">
                </div>
            </div>
            <div class="form-group">	
				<label class="col-sm-3 control-label">证件号码：</label>
				<div class="col-sm-8">
					<input id="empId" name="empId" th:field="*{empId}" class="form-control" type="text" readonly="readonly">
				</div>
			</div>
            <div class="form-group">	
                <label class="col-sm-3 control-label">学历：</label>
                <div class="col-sm-8">
					<select id="empEdu" class="form-control m-b" th:with="type=${@dict.getType('pm_edu_type')}">
	                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{empEdu}"></option>
	                </select>
				</div>
            </div>
            <div class="form-group">	
                <label class="col-sm-3 control-label">学位：</label>
                <div class="col-sm-8">
					<select id="empDeg" class="form-control m-b" th:with="type=${@dict.getType('pm_graduate_type')}">
	                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{empDeg}"></option>
	                </select>
				</div>
            </div>
            <div class="form-group">	
                <label class="col-sm-3 control-label">毕业院校：</label>
                <div class="col-sm-8">
                    <input id="empSch" name="empSch" th:field="*{empSch}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">	
                <label class="col-sm-3 control-label">专业名称：</label>
                <div class="col-sm-8">
                    <input id="empMajor" name="empMajor" th:field="*{empMajor}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">	
                <label class="col-sm-3 control-label">专业类别：</label>
                <div class="col-sm-8">
					<select id="empMajorType" class="form-control m-b" th:with="type=${@dict.getType('pm_major_type')}">
	                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{empMajorType}"></option>
	                </select>
				</div>
            </div>
			 <div class="form-group">
				<label class="col-sm-3 control-label">日期： </label>
				<div class="col-sm-8 form-inline select-time">
						<input type="text" class="form-control time-input" id="startTime" placeholder="开始时间" name="params[beginTime]" th:value="${#dates.format(eduInfo.empEnroDt, 'yyyy-MM-dd')}" />
						<span class="form-control text-center" style="border:0;">至</span>
						<input type="text" class="form-control time-input" id="endTime" placeholder="结束时间" name="params[endTime]" th:value="${#dates.format(eduInfo.empGradDt, 'yyyy-MM-dd')}"/>
				</div>
			</div>
			
		</form>
    </div>
    <div th:include="include::footer"></div>
    <script type="text/javascript">
    
		var prefix = ctx + "pm/eduInfo";
		$("#form-eduInfo-edit").validate({
			rules:{
				empId:{
        			required:true
        		},
        		empNm:{
        			required:true
        		},
        		empEdu:{
        			required:true
        		},
        		empSch:{
        			required:true
        		},
        		empMajor:{
        			required:true
        		},
        		empMajorType:{
        			required:true
        		},
        		empDeg:{
        			required:true
        		},
        		empEnroDt:{
        			required:true
        		},
        		empGradDt:{
        			required:true
        		}
        	}
		});
		
		function submitHandler() {
	        if ($.validate.form()) {
                var result = checkDateOverlap();
                if (result.toString() === "1") {
                    edit();
                } else {
                    $.modal.alertError("时间重叠");
                }
	        }
	    }

        function checkDateOverlap() {
            var flag = "";
            var empEnroDt = $("#startTime").val();
            var empGradDt = $("#endTime").val();
            var empId = $("input[name='empId']").val();
            var empSn = $("input[name='empSn']").val();
            $.ajax({
                cache : true,
                type : "POST",
                url : ctx + "pm/eduInfo/checkDate",
                data : {
                    "empId": empId,
                    "startDate": empEnroDt,
                    "endDate": empGradDt,
                    "operationType": "edit",
                    "id": empSn
                },
                async : false,
                error : function(request) {
                    $.modal.alertError("时间重叠");
                },
                success : function(data) {
                    flag = data;
                }
            });
            return flag;
        }
		
		function edit() {
			var empSn = $("input[name='empSn']").val();
			var empId = $("input[name='empId']").val();
        	var empNm = $("input[name='empNm']").val();
        	var empEdu = $("#empEdu option:selected").val();
        	var empDeg = $("#empDeg option:selected").val();
        	var empSch = $("input[name='empSch']").val();
        	var empMajor = $("input[name='empMajor']").val();
        	var empMajorType = $("#empMajorType option:selected").val();
        	var empEnroDt = $("#startTime").val();
        	var empGradDt = $("#endTime").val();
        	$.ajax({
        		cache : true,
        		type : "POST",
        		url : ctx + "pm/eduInfo/edit",
        		data : {
        			"empSn": empSn,
        			"empId": empId,
        			"empNm": empNm,
        			"empEdu": empEdu,
        			"empDeg": empDeg,
        			"empSch": empSch,
        			"empMajor": empMajor,
        			"empMajorType": empMajorType,
        			"empEnroDt": empEnroDt,
        			"empGradDt": empGradDt
        		},
        		async : false,
        		error : function(request) {
        			$.modal.alertError("系统错误");
        		},
        		success : function(data) {
        			$.operate.saveSuccess(data);
        		}
        	});
        }
	</script>
</body>
</html>
